﻿@using KRM.Core

@using KRM.Core.Library
@model IEnumerable<KRM.Core.tblBookNotification>
@{
    var currentUser = Users.Current(User.Identity.Name);
}
<li>
    <p>You have @ViewBag.CountUnread new notifications</p>
</li>
<li>
    <ul class="dropdown-menu-list scroller" id="listbooknotificontent" style="height: 250px; overflow: auto; width: auto;">
        @foreach (var item in @Model)
        {
            if (@item.tblBook.PersonalId == @currentUser.HRPersonalId)
            {
            <li>
                <a href="/HolidayRequest/ViewHolidayRequest/@item.BookId" style="@(item.Read == false ? "background-color:rgb(252, 217, 207)" : "")">
                    <span class="photo">
                        <img src="/Upload/Avatar/@(item.tblPersonalFrom.Image ?? "avatar-default.jpg")" alt=""></span>
                    <span class="subject">
                        <span class="from">@item.tblPersonalFrom.FullName </span>
                        @Html.Raw(@item.HtmlNotification(User.Identity.Name))
                    </span>
                    <span class="time">at @item.DateCreated</span>
                    <span class="notification-action"><span class="@item.tblBookCommentType.LabelClass">@(item.tblBookCommentType == null ? "" : item.tblBookCommentType.Name)</span>
                    </span>

                </a>
            </li>
            }
            else
            {
            <li>
                <a href="/HolidayManagement/ViewHolidayRequest/@item.BookId" style="@(item.Read == false ? "background-color:rgb(252, 217, 207)" : "")">
                    <span class="photo">
                        <img src="/Upload/Avatar/@(item.tblPersonalFrom.Image ?? "avatar-default.jpg")" alt=""></span>
                    <span class="subject">
                        <span class="from">@item.tblPersonalFrom.FullName </span>
                        @Html.Raw(@item.HtmlNotification(User.Identity.Name))
                    </span>
                    <span class="time">at @item.DateCreated</span>
                    <span class="notification-action"><span class="@item.tblBookCommentType.LabelClass">@(item.tblBookCommentType == null ? "" : item.tblBookCommentType.Name)</span>
                    </span>

                </a>
            </li>
            }

        }
    </ul>
</li>
<li class="external">
    <a href="/Notification/" style="padding-bottom: 10px !important">See all notifications <i class="m-icon-swapright"></i></a>
</li>
@{
    if (ViewBag.MarkRead)
    {
        var db = new HREntities();
        var lstId = Model.Where(p => p.Read == false).Select(p => p.Id).ToList();
        foreach (var item in db.tblBookNotifications.Where(p => lstId.Contains(p.Id)))
        {
            item.Read = true;
        }
        db.SaveChanges();
    <script>loadCountBookNotiUnread();</script>
    }
    
}